package com.jiayuge.poiStudy.service;

import com.aspose.words.Document;

import java.io.File;
import java.io.FileOutputStream;

public class ToPDF {
    public static void TextWordToPdf(String wordPath, String pdfPath) throws Exception {
        FileOutputStream os = null;
        try {
            long old = System.currentTimeMillis();
            File file = new File(pdfPath);
            os = new FileOutputStream(file);
            Document doc = new Document(wordPath);
            doc.save(os, com.aspose.words.SaveFormat.PDF);
            long now = System.currentTimeMillis();
            System.out.println("共耗时：" + ((now - old) / 1000.0) + "秒"); // 转化用时
        }finally {
            if(os!=null) {
                os.close();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        String wordPath = "D:\\project\\poi-study\\src\\main\\java\\com\\jiayuge\\poiStudy\\files\\table.docx";
        String pdfPath = "D:\\project\\poi-study\\src\\main\\java\\com\\jiayuge\\poiStudy\\files\\table.pdf";
        TextWordToPdf(wordPath,pdfPath);
    }
}
